<?php

/**
 * EReallySimpleSlideshow class
 *
 * @author Julot <andy.julot@gmail.com>
 * @since Thursday, July 14, 2011. 11:07 AM
 */
class EReallySimpleSlideshow {

	protected static function register() {
		$cs = Yii::app()->clientScript;
		$cs->registerCoreScript('jquery');
		$assets = Yii::app()->extensionPath . '/EReallySimpleSlideshow/';
		$aUrl = Yii::app()->getAssetManager()->publish($assets);
		$cs->registerScriptFile($aUrl . '/jquery.rs.slideshow.min.js');
	}

	public static function add($selector, $opts=array()) {
		self::register();
		$options = CJavaScript::encode($opts);
		$script = '$("' . $selector . '").rsfSlideshow(' . $options .');';
		$cs = Yii::app()->clientScript;
		$id = __CLASS__ . '_' . sprintf("%x", crc32($selector . $options));
		$cs->registerScript($id, $script, CClientScript::POS_READY);
	}

}
